package Demo3;

import java.io.*;

public class CountFile extends Thread {
    private char name;

    public CountFile(char name) {
        this.name = name;
    }
    @Override
    public void run() {
        System.out.println("开始统计文件夹: " + name);
        int count = 0;
        String str = "D:\\text\\" + name;
        File file = new File(str);
        File[] files = file.listFiles();
        for (File f : files) {
            try {
                FileReader fileReader = new FileReader(f);
                int fileChar = 0;
                while ((fileChar = fileReader.read()) != -1) {
                    if (fileChar == 'a') {
                        count++;
                    }
                }
                fileReader.close();
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println(name + " 文件夹下有: " + count + " 文件");
    }
}